package com.zerox.payment.controller;

import com.zerox.commons.utils.ResponseResult;
import com.zerox.payment.domain.pojo.Payment;
import com.zerox.payment.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @auth wzy
 * @date 2023/3/15 10:48
 */
@Slf4j
@RestController
@RequestMapping("/payment")
public class PaymentController {

    @Autowired
    private PaymentService paymentService;

    @PostMapping("/create")
    public ResponseResult create(@RequestBody Payment payment){
        boolean result = paymentService.save(payment);

        log.info("*****插入结果："+result);

        if (result){
           return ResponseResult.success("插入数据库成功");
        }

        return ResponseResult.error("插入数据库失败");
    }

    @GetMapping("/{id}")
    public ResponseResult getPayment(@PathVariable Long id){
        Payment payment = paymentService.getById(id);
        log.info("*****查询结果："+payment);
        return ResponseResult.success(payment);
    }

}
